import React, { Component } from 'react'
import { createStore, applyMiddleware, compose } from 'redux'
import { Provider } from 'react-redux';
import thunkMiddleware from 'redux-thunk';
//import logger from 'redux-logger';
import Immutable from 'immutable'
import reducers from '../reducers/reducer'
import LoadingToast from '../components/LoadingToast'
const initialState=Immutable.fromJS({});
const createStoreWithMiddleware = applyMiddleware(
    thunkMiddleware
    //,logger()
)(createStore)

var prevurl="/";
const store = createStoreWithMiddleware(reducers,initialState);

export default class App extends Component {

    constructor(props){
        super(props);
    }

    componentWillUpdate(a){
        //点击时重新加载统计代码
        if(a.location.pathname!=prevurl){
            var cnzzimg=document.createElement("img");
            cnzzimg.src=document.location.protocol+"//c.cnzz.com/wapstat.php?r=&siteid=1260048704&rnd="+Math.ceil(Math.random()*10000);;
            cnzzimg.style.display="none";
            document.body.appendChild(cnzzimg);
            prevurl=a.location.pathname;
        }
    }
  render() {
      return (
        <Provider store={store}>
           <div style={{height:"100%"}}>
               <LoadingToast/>
               {this.props.children}
           </div>
        </Provider>
    )
  }
}
